package vip.finance.makemoney.service.impl;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import vip.finance.makemoney.apiSpider.snowball.SnowRealTimeResult;
import vip.finance.makemoney.common.vo.UserInfo;

import java.util.concurrent.TimeUnit;

/**
 * @author yangbin
 * @since 2023-02-10
 */
@Service
public class RedisService {
    String KEY_PREFIX = "make-money";

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;

    public void saveRealTime(String code, SnowRealTimeResult.DataBean.ItemsBean result) {
        redisTemplate.opsForValue().set(KEY_PREFIX + ":real-time:" + code, result);
    }

    public SnowRealTimeResult.DataBean.ItemsBean getSnowRealTime(String code) {
        return (SnowRealTimeResult.DataBean.ItemsBean) redisTemplate.opsForValue().get(KEY_PREFIX + ":real-time:" + code);
    }

    public UserInfo getUserInfo(String key) {
        return (UserInfo) redisTemplate.opsForValue().get(key);
    }

    public void saveUserInfo(String key, UserInfo userInfo, long timeout, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, userInfo, timeout, timeUnit);
    }
}
